package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.Brand;
import com.sailfish.springbootdemo.service.db1.BrandService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/brand")
@CrossOrigin
public class BrandController {

    @Autowired
    private BrandService brandService;

    @PostMapping("/getAllBrand")
    public Result getAllBrand(String searchValue) {
        try {
            return ResultUtil.success(brandService.getAllBrand(searchValue));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deleteBrandById")
    public Result deleteBrandById(Integer brandId) {
        return brandService.deleteBrandById(brandId);
    }

    @PostMapping("/addOrUpdateBrand")
    public Result addOrUpdateBrand(String mode, Brand brand) {
        return brandService.addOrUpdateBrand(mode, brand);
    }

    @PostMapping("/getAllBrandByDeviceType")
    public Result getAllBrandByDeviceType(Integer deviceType, Integer isTechOwn, Integer status) {
        return brandService.getAllBrandByDeviceType(deviceType, isTechOwn, status);
    }

    @PostMapping("/getAllBrandByDeviceTypes")
    public Result getAllBrandByDeviceTypes(String deviceTypes, Integer isTechOwn, Integer status) {
        return brandService.getAllBrandByDeviceTypes(deviceTypes, isTechOwn, status);
    }
}
